Titanium.UI.setBackgroundColor('#000');
var window= Ti.UI.createWindow();



var longitudeLabel = Ti.UI.createLabel({
	top:10,
	left:10,
	text:'No text'
});

var latitudeLabel = Ti.UI.createLabel({
	top:40,
	left:10,
	text:'No text'
});

var speedLabel = Ti.UI.createLabel({
	top:40,
	left:10,
	text:'No text'
});

if (Titanium.Geolocation.locationServicesEnabled === false)
{
	Titanium.UI.createAlertDialog({title:'My app', message:'Your device has geo turned off - turn it on.'}).show();
}
else
{
	Ti.Geolocation.preferredProvider = "gps";
	Titanium.Geolocation.distanceFilter = 10;
	Titanium.Geolocation.getCurrentPosition( function(e) {
			if (!e.success) {
				alert('Could not retrieve location');
				return;
			}
			var longitude = e.coords.longitude;
			var latitude = e.coords.latitude;
			
			longitudeLabel.text = longitude;
			latitudeLabel.text = latitude;
	});
	
	
	Ti.Geolocation.addEventListener('location', function(e) {
	  if (e.error) {
	  	latitudeLabel = "error";
	    Ti.API.error('geo - position' + e.error);
	    return;
	  }
	  var latitude = e.coords.latitude;
	  var longitude = e.coords.longitude;
	  var altitude = e.coords.altitude;
	  var accuracy = e.coords.accuracy;
	  var altitudeAccuracy = e.coords.altitudeAccuracy;
	  var heading = e.coords.heading;
	  var speed = e.coords.speed;
	  var timestamp = e.coords.timestamp;
	  Ti.API.info('geo - position');
	  Ti.API.info(' - latitude: ' + latitude);
	  Ti.API.info(' - longitude: ' + longitude);
	  Ti.API.info(' - altitude: ' + altitude);
	  Ti.API.info(' - accuracy: ' + accuracy);
	  Ti.API.info(' - altitudeAccuracy: ' + altitudeAccuracy);
	  Ti.API.info(' - heading: ' + heading);
	  Ti.API.info(' - speed: ' + speed);
	  Ti.API.info(' - timestamp: ' + timestamp);
	  
	  longitudeLabel.text = longitude;
	  latitudeLabel.text = latitude;
	  speedLabel.text = speed;
	});
}

window.add(longitudeLabel);
window.add(latitudeLabel);

window.open();